#include <bits/stdc++.h>
using namespace std;

constexpr int n = 1000;
int a[n][n], b[n][n], c[n][n];

void benchmark(const string &name, const auto &func) {
  auto start = chrono::high_resolution_clock::now();
  func();
  auto end = chrono::high_resolution_clock::now();
  auto duration = chrono::duration_cast<chrono::milliseconds>(end - start);
  cout << format("{} execution time: {} ms\n", name, duration.count());
}
int main() {
  for (auto &row : a) {
    for (auto &x : row) x = rand();
  }
  for (auto &row : b) {
    for (auto &x : row) x = rand();
  }

  benchmark("ikj", [&]() {
    for (int i = 0; i < n; ++i) {
      for (int k = 0; k < n; ++k) {
        for (int j = 0; j < n; ++j) {
          c[i][j] += a[i][k] * b[k][j];
        }
      }
    }
  });

  benchmark("ijk", [&]() {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        for (int k = 0; k < n; ++k) {
          c[i][j] += a[i][k] * b[k][j];
        }
      }
    }
  });
  
  benchmark("jki", [&]() {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
          c[i][j] += a[i][k] * b[k][j];
        }
      }
    }
  });
}